package com.zx.mobile.service.proxy;

import com.zx.map.service.model.HistoryPayCardInfoModel;
import com.zx.mobile.MobileCommonHelper;
import com.zx.mobile.context.DirectoryInfoContext;

import java.util.List;

public class HistoryPayCardProxy {

    public static List<HistoryPayCardInfoModel> transformHistoryPayCard(
            List<HistoryPayCardInfoModel> list) {
        for (HistoryPayCardInfoModel oo : list) {
            StringBuffer tempName = new StringBuffer("");
            StringBuffer tempAccount = new StringBuffer("");
            if (MobileCommonHelper.CARDTYPE_DEBIT.equals(oo.getDebitFlag()))// 借记卡
            // 才有用户名信息
            {
                for (int i = 0; i < oo.getBankName().length(); i++) {
                    if (i >= 1) {
                        tempName.append("*");
                    } else {
                        tempName.append(oo.getBankName().charAt(i));
                    }
                }
                oo.setShortName(tempName.toString());
            }
            for (int j = 0; j < oo.getBankAccount().length(); j++) {
                if (j >= 4 && j < oo.getBankAccount().length() - 4) {
                    tempAccount.append("*");
                } else {
                    tempAccount.append(oo.getBankAccount().charAt(j));
                }
            }
            oo.setShortCardNo(tempAccount.toString());
            oo.setLastCardNo(oo.getBankAccount().substring(
                    oo.getBankAccount().length() - 4));
        }
        return list;
    }


    /**
     * 仅供前端接口调用使用
     *
     * @param list
     * @return
     */
    public static List<HistoryPayCardInfoModel> transformHistoryPayCardForApp(
            List<HistoryPayCardInfoModel> list) {
        String bankImgPrefix = "/images/mobile/";
        for (HistoryPayCardInfoModel oo : list) {
            StringBuffer tempName = new StringBuffer("");
            StringBuffer tempAccount = new StringBuffer("");
            try {
                oo.setBankLegalName(DirectoryInfoContext.getCaptionByKeyAndValue("2100", oo.getBankCode()));
            }catch (Exception e){
                oo.setBankLegalName("未知");
            }

            //设置图片内容为绝对路径
            oo.setBankImgPath(bankImgPrefix + oo.getBankCode() + ".png");
            if (MobileCommonHelper.CARDTYPE_DEBIT.equals(oo.getDebitFlag()))// 借记卡
            // 才有用户名信息
            {
                for (int i = 0; i < oo.getBankName().length(); i++) {
                    if (i >= 1) {
                        tempName.append("*");
                    } else {
                        tempName.append(oo.getBankName().charAt(i));
                    }
                }
                oo.setShortName(tempName.toString());
            }
            for (int j = 0; j < oo.getBankAccount().length(); j++) {
                if (j >= 4 && j < oo.getBankAccount().length() - 4) {
                    tempAccount.append("*");
                } else {
                    tempAccount.append(oo.getBankAccount().charAt(j));
                }
            }
            oo.setShortCardNo(tempAccount.toString());
            oo.setLastCardNo(oo.getBankAccount().substring(
                    oo.getBankAccount().length() - 4));
        }
        return list;
    }

}
